/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkg1241316_webbrowser;

import WebBrowser_Cores.QuetThongTin;
import WebBrowser_Cores.ScanWebbrowser;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

/**
 *
 * @author Administrator
 */
public class frmMain extends javax.swing.JFrame {

    //<editor-fold desc="Khai báo biến toàn cục">
    /**
     * Kiểu người dùng chọn hiển thị thêm 1 node vào cây bên phải nếu = -1:
     * người dùng chưa chọn nếu = 1: người dùng chọn kiểu thêm node đang được
     * chọn từ cây nếu = 2: người dùng chọn kiểu thêm node lấy được từ XPath
     */
    int Loai = -1;
    DefaultTreeModel modelJtreeChon = null;
    //</editor-fold>

    /**
     * Creates new form frmMain
     */
    public frmMain() {
        initComponents();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jSplitPane2 = new javax.swing.JSplitPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTreeChon = new javax.swing.JTree();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtXpath = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextAreacodeHtml = new javax.swing.JTextArea();
        jButtonXemTrenWeb = new javax.swing.JButton();
        jButtonNext = new javax.swing.JButton();
        jButtonNextAll = new javax.swing.JButton();
        jButtonXoaNode = new javax.swing.JButton();
        jButtonLuu = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTreeHienThi = new javax.swing.JTree();
        jPanel4 = new javax.swing.JPanel();
        txtlink = new javax.swing.JTextField();
        btnHienThi = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jSplitPane1.setDividerLocation(200);

        jSplitPane2.setDividerLocation(200);

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        jTreeChon.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jTreeChon.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                jTreeChonValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(jTreeChon);

        jSplitPane2.setRightComponent(jScrollPane2);

        jLabel1.setText("Xpath tương ứng");

        txtXpath.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtXpathActionPerformed(evt);
            }
        });

        jLabel2.setText("Code html tương ứng");

        jTextAreacodeHtml.setColumns(20);
        jTextAreacodeHtml.setRows(5);
        jScrollPane3.setViewportView(jTextAreacodeHtml);

        jButtonXemTrenWeb.setText("Xem như Webbrowser");
        jButtonXemTrenWeb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonXemTrenWebActionPerformed(evt);
            }
        });

        jButtonNext.setText(">");
        jButtonNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNextActionPerformed(evt);
            }
        });

        jButtonNextAll.setText(">>");

        jButtonXoaNode.setText("Xóa Node >");

        jButtonLuu.setText("Lưu >");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtXpath, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonXemTrenWeb)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jButtonLuu, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonNextAll, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonNext, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonXoaNode, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jLabel1))
                .addGap(0, 31, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtXpath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addComponent(jButtonXemTrenWeb)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonNext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonNextAll)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonXoaNode)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonLuu)
                .addContainerGap(51, Short.MAX_VALUE))
        );

        jSplitPane2.setLeftComponent(jPanel3);

        jSplitPane1.setRightComponent(jSplitPane2);

        treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        jTreeHienThi.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jTreeHienThi.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                jTreeHienThiValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jTreeHienThi);

        jSplitPane1.setLeftComponent(jScrollPane1);

        btnHienThi.setText("Hiển Thi");
        btnHienThi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHienThiActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txtlink, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnHienThi)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addGap(0, 11, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtlink, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnHienThi)))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 590, Short.MAX_VALUE)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1))
        );

        jTabbedPane1.addTab("tab1", jPanel1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 590, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 464, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("tab2", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    Element ElementdangchonXpath;

    /**
     * Sự kiện khi bấm enter vào ô Xpath
     *
     * @param evt
     */
    private void txtXpathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtXpathActionPerformed
        // TODO add your handling code here:
        //lấy code html từ xpath
        try {
            ScanWebbrowser m_Handle = new QuetThongTin();
            List<String> NodeContent = m_Handle.GetContentTagFromXpath(ReadHtmlFromURL(txtlink.getText().trim()), txtXpath.getText().trim());
            String html = ConvertStringFromListString(NodeContent);
            Document doc = Jsoup.parse(html);
            //lấy thông tin node
            ElementdangchonXpath = doc.body();
            jTextAreacodeHtml.setText(ElementdangchonXpath.html());

        } catch (Exception ex) {
        }
    }//GEN-LAST:event_txtXpathActionPerformed

    //<editor-fold desc="Sự kiện khi bấm vào nút Hiển thị">
    /**
     * Hiển thị code html thành các node của 1 cây rồi hiện lên treeHienThi
     *
     * @param evt
     */
    private void btnHienThiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHienThiActionPerformed

        try {
            //Lấy code html từ đương link
            if (txtlink.getText() != null || txtlink.getText().trim().length() > 0) {
                String html = ReadHtmlFromURL(txtlink.getText().trim());
                if (html != null) {
                    Loai = 1;
                    //chuyển html thành danh sách các Element
                    Document doc = Jsoup.parse(html);
                    Element ElementROOT = doc.children().get(0);
                    //chuyển thông tin node thành NodeTree
                    NodeTree nodetree = new NodeTree();
                    nodetree.setTenNode(ElementROOT.nodeName());
                    nodetree.setInfomationNode(ElementROOT);
                    nodetree.setDanhSachNodeCon(ElementROOT.children());
                    DefaultMutableTreeNode noderoot = new DefaultMutableTreeNode(nodetree);
                    for (Element itemnodeCha : ElementROOT.children()) {
                        DefaultMutableTreeNode nodecon = TimNodeCon(itemnodeCha);
                        noderoot.add(nodecon);
                    }
                    DefaultTreeModel model = new DefaultTreeModel(noderoot);

                    //hiển thị lên TreeHienThi
                    jTreeHienThi.setModel(model);
                }
            }
        } catch (Exception ex) {
        }
    }//GEN-LAST:event_btnHienThiActionPerformed
    //</editor-fold>
    DefaultMutableTreeNode selectednode = null;

    /**
     * Chọn 1 node trên treeHienThi
     *
     * @param evt
     */
    private void jTreeHienThiValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jTreeHienThiValueChanged
        // TODO add your handling code here:
        try {
            selectednode = (DefaultMutableTreeNode) jTreeHienThi.getLastSelectedPathComponent();

            //hiển thị thông tin sang các control tương ứng.
            HienThiThongTinTuTreeChon();
        } catch (Exception ex) {
        }
    }//GEN-LAST:event_jTreeHienThiValueChanged

    private void jButtonNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNextActionPerformed
        // TODO add your handling code here:
        switch (Loai) {
            case 1:

                if (selectednode != null) {
                    if (nodecanthem == null) {
                        modelJtreeChon = (DefaultTreeModel) jTreeChon.getModel();
                        int n = modelJtreeChon.getChildCount(modelJtreeChon.getRoot());
                        if (n == 0) {
                            DefaultMutableTreeNode node = new DefaultMutableTreeNode(txtlink.getText().trim());
                            node.add(selectednode);
                            DefaultTreeModel tree = new DefaultTreeModel(node);
                            jTreeChon.setModel(tree);
                            modelJtreeChon = (DefaultTreeModel) jTreeChon.getModel();
                        } else {
                            DefaultMutableTreeNode node = (DefaultMutableTreeNode) modelJtreeChon.getRoot();
                            node.insert(selectednode, node.getIndex(node.getLastChild()) + 1);
                            modelJtreeChon.reload(node);

                        }
                    } else {

                        //hiển thị node này sang bên Jtree bên phải.
                        int n = nodecanthem.getIndex(nodecanthem.getLastChild()) + 1;
                        nodecanthem.insert(selectednode, n);
                        modelJtreeChon.reload(nodecanthem);
                    }

                }

                break;
            case 2:
                if (ElementdangchonXpath != null && nodecanthem != null) {
                    //lấy danh sách các node con của
                    DefaultMutableTreeNode nodecon = TimNodeCon(ElementdangchonXpath);
                    NodeTree node = new NodeTree();
                    node.setInfomationNode(ElementdangchonXpath);
                    node.setTenNode(ElementdangchonXpath.nodeName());
                    DefaultMutableTreeNode nodeTemp = new DefaultMutableTreeNode(node);
                    nodecanthem.insert(nodeTemp, nodecanthem.getIndex(nodecanthem.getLastChild()) + 1);
                }
                break;
            default:
                ElementdangchonXpath = null;
                selectednode = null;
                nodecanthem = null;

                break;
        }
    }//GEN-LAST:event_jButtonNextActionPerformed
    DefaultMutableTreeNode nodecanthem = null;

    /**
     * Chọn 1 node của cây bên phải
     *
     * @param evt
     */
    private void jTreeChonValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jTreeChonValueChanged
        // TODO add your handling code here:
        try {
            nodecanthem = (DefaultMutableTreeNode) jTreeChon.getLastSelectedPathComponent();
        } catch (Exception ex) {
        }
    }//GEN-LAST:event_jTreeChonValueChanged
    public String m_htmlInfo = null;
    Show frm = null;
    private void jButtonXemTrenWebActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonXemTrenWebActionPerformed
        // TODO add your handling code here:
        m_htmlInfo = jTextAreacodeHtml.getText().trim();
        if (frm == null) {
            frm = new Show(this);
            frm.setSize(500, 600);
        }
        frm.setVisible(true);
    }//GEN-LAST:event_jButtonXemTrenWebActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmMain().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnHienThi;
    private javax.swing.JButton jButtonLuu;
    private javax.swing.JButton jButtonNext;
    private javax.swing.JButton jButtonNextAll;
    private javax.swing.JButton jButtonXemTrenWeb;
    private javax.swing.JButton jButtonXoaNode;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextAreacodeHtml;
    private javax.swing.JTree jTreeChon;
    private javax.swing.JTree jTreeHienThi;
    private javax.swing.JTextField txtXpath;
    private javax.swing.JTextField txtlink;
    // End of variables declaration//GEN-END:variables

    //<editor-fold desc="Đọc code html từ đường dẫn url">
    private String ReadHtmlFromURL(String url) {
        String strResult = null;
        try {
            //hiển thị source
            URL yahoo = new URL(url);
            URLConnection yc = yahoo.openConnection();

            try (BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    yc.getInputStream()))) {
                strResult = "";
                String inputLine = "";
                while ((inputLine = in.readLine()) != null) {
                    strResult += inputLine;
                }
            }
            strResult = strResult.replaceAll(">", "> \r\n");
        } catch (Exception ex) {
        }
        return strResult;
    }
//</editor-fold>

    //<editor-fold desc="Tìm những node con của node cha">
    /**
     * Tìm những node con của node cha
     *
     * @param nodecha
     * @return
     */
    private DefaultMutableTreeNode TimNodeCon(Element nodecha) {
        DefaultMutableTreeNode nodeCha = null;
        try {
            NodeTree NutCha = new NodeTree();
            NutCha.setTenNode(nodecha.tagName());
            NutCha.setInfomationNode(nodecha);
            NutCha.setDanhSachNodeCon(nodecha.children());

            nodeCha = new DefaultMutableTreeNode(NutCha);
            for (Element nodecon : nodecha.children()) {
                nodeCha.add(TimNodeCon(nodecon));
            }
        } catch (Exception ex) {
        }
        return nodeCha;
    }
    //</editor-fold>

    /**
     * Hiển thị thông tin khi người dung nhấp vào 1 node của TreeChon
     */
    private void HienThiThongTinTuTreeChon() {
        try {
            if (selectednode != null) {
                //hiển thị thông tin
                NodeTree node = (NodeTree) selectednode.getUserObject();
                jTextAreacodeHtml.setText(node.getInfomationNode().html());
            }
        } catch (Exception ex) {
        }
    }

    /**
     * Chuyễn danh sách các chuỗi thành 1 chuỗi duy nhất
     *
     * @param lst
     * @return
     */
    private String ConvertStringFromListString(List<String> lst) {
        String strResult = null;
        if (lst.size() > 0) {
            for (String sitem : lst) {
                if (strResult == null) {
                    strResult = sitem;
                } else {
                    strResult += "\r\n" + sitem;
                }
            }
        }
        return strResult;
    }
}
